<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>全部图书信息</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/jquery-3.2.1.js"></script>
    <script src="js/bootstrap.min.js" ></script>
    <script>
        $(function () {
            $('#header').load('admin_header.html');
        })
        /*提示是否删除图书*/
        function del() {
            if(confirm("确实要删除该用户吗？")){
                alert("已经删除！");
            }else {
                window.event.returnValue = false;
                alert("已经取消了删除操作");
            }
        }
    </script>
</head>

<body background="img/book1.jpg" style=" background-repeat:no-repeat ;
background-size:100% 100%;
background-attachment: fixed;">

<div id="header"></div>

<%--图书模糊查询--%>
<div style="padding: 70px 600px 10px">
    <form   method="post" action="querybook.html"   id="searchform">
        <div class="input-group">
           <input type="text" placeholder="输入图书名或作者名" class="form-control" id="search" name="bookName" class="form-control" >
            <span class="input-group-btn">
                <input type="submit" value="搜索" class="btn btn-success">
            </span>
        </div>
    </form>

    <form   method="post" action="querybook2.html"   >
        <div class="input-group">
            <select class="form-control"   id="search2" name="classId" >
                <c:forEach items="${classList}" var="class">
                    <option value="${class.class_id}">类别${class.class_id}-${class.class_name}</option>
               </c:forEach>
            </select>
            <span class="input-group-btn">
                <input type="submit" value="搜索" class="btn btn-success">
            </span>
        </div>
    </form>
    <script>
        $("#searchform").submit(function () {
            var val=$("#search").val();
            if(val==''){
                alert("请输入书名、作者其中一样！");
                return false;
            }
        })

    </script>
</div>
<%--接受提示信息--%><div style="position: relative;top: 10%">

<c:if test="${!empty succ}">
    <div class="alert alert-success alert-dismissable">
        <button type="button" class="close" data-dismiss="alert"
                aria-hidden="true">
            &times;
        </button>
        ${succ}
    </div>
</c:if>
<c:if test="${!empty error}">
    <div class="alert alert-danger alert-dismissable">
        <button type="button" class="close" data-dismiss="alert"
                aria-hidden="true">
            &times;
        </button>
        ${error}
    </div>
</c:if>
</div>
<%--全部图书--%>
<div class="panel panel-default" style="width: 90%;margin-left: 5%">
    <div class="panel-heading" style="background-color: #fff">
        <h3 class="panel-title">
            全部图书
        </h3>
    </div>
    <div class="panel-body">
        <table class="table table-hover">
            <thead>
            <tr>
                <th>图书号</th>
                <th>书名</th>
                <th>作者</th>
                <th>出版社</th>
                <th>ISBN</th>
                <th>价格</th>
                <th>剩余数量</th>
                <th>详情</th>
                <th>编辑</th>
                <th>删除</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${books}" var="book">
            <tr>
                <td>${book.bookId}</td>
                <td>${book.name}</td>
                <td>${book.author}</td>
                <td>${book.publish}</td>
                <td>${book.isbn}</td>
                <td>${book.price}</td>
                <td>${book.number}</td>
                <td><a href="admin_book_detail.html?bookId=${book.bookId}">
                    <button type="button" class="btn btn-success btn-xs">详情</button>
                </a></td>
                <td><a href="updatebook.html?bookId=${book.bookId}&bookName=${bookName}&classId=${classId}&currentPage=${page.currentPage}">
                    <button type="button" class="btn btn-info btn-xs">编辑</button></a>
                </td>
                <td><a href="deletebook.html?bookId=${book.bookId}&bookName=${bookName}&classId=${classId}&currentPage=${page.currentPage}" onclick="return del()">
                    <button type="button" class="btn btn-danger btn-xs">删除</button></a>
                </td>
            </tr>
            </c:forEach>

            <tr>
                 <td colspan="4"></td>
                <td colspan="3">当前为第${page.currentPage}页,共${page.totalPage}页</td>
                <td colspan="3">
                    <c:choose>
                        <c:when test="${page.hasPrePage}">
                            <c:if test="${empty bookName && empty classId}">
                                <a href="${url}?currentPage=1">首页</a> |
                                <a href="${url}?currentPage=${page.currentPage -1 }">上一页</a>
                            </c:if>
                            <c:if test="${!empty bookName && empty classId}">
                                <a href="${url}?bookName=${bookName}&currentPage=1">首页</a> |
                                <a href="${url}?bookName=${bookName}&currentPage=${page.currentPage -1 }">上一页</a>
                            </c:if>
                            <c:if test="${empty bookName && !empty classId}">
                                <a href="${url}?classId=${classId}&currentPage=1">首页</a> |
                                <a href="${url}?classId=${classId}&currentPage=${page.currentPage -1 }">上一页</a>
                            </c:if>
                        </c:when>
                        <c:otherwise>
                            首页 | 上一页
                        </c:otherwise>
                    </c:choose>

                    <c:choose>
                        <c:when test="${page.hasNextPage}">
                            <c:if test="${empty bookName && empty classId}">
                                <a href="${url}?currentPage=${page.currentPage + 1 }">下一页</a> |
                                <a href="${url}?currentPage=${page.totalPage }">尾页</a>
                            </c:if>
                            <c:if test="${!empty bookName && empty classId}">
                                <a href="${url}?bookName=${bookName}&currentPage=${page.currentPage + 1 }">下一页</a> |
                                <a href="${url}?bookName=${bookName}&currentPage=${page.totalPage }">尾页</a>
                            </c:if>
                            <c:if test="${empty bookName && !empty classId}">
                                <a href="${url}?classId=${classId}&currentPage=${page.currentPage + 1 }">下一页</a> |
                                <a href="${url}?classId=${classId}&currentPage=${page.totalPage }">尾页</a>
                            </c:if>
                        </c:when>
                        <c:otherwise>
                            下一页 | 尾页
                        </c:otherwise>
                    </c:choose>
                </td>
            </tr>

            </tbody>
        </table>



    </div>
</div>
</body>
</html>



<%--管理员   全部图书--%>